<template>
	<view>
		<swiper autoplay circular indicator-dots class="swiper" v-if="banner">
			<swiper-item v-for="i in banner">
				<image mode="aspectFill" :src="i"></image>
			</swiper-item>
		</swiper>
		<tygoods :list="list"></tygoods>
		<view class="hasmore">{{hasmore?'加载中':'没有更多了'}}</view>
	</view>
</template>

<script>
	import tygoods from './components/tygoods'
	export default {
		components: {
			tygoods
		},
		data() {
			return {
				page: 1,
				limit: 10,
				hasmore: true,
				list: [],
				banner:''
			}
		},
		onLoad(op) {
			//type  1体验区 2推广区 3新会员专享
			this.type = op.type
			this.mch_id = op.p_mch_id
			if (this.type == 3) {
				uni.setNavigationBarTitle({
					title: '新客会员专享'
				})
				this.mch_id = uni.getStorageSync('s_mch_id') || 0   
			}
			this.getList()
			this.getBanner()
		},
		onReachBottom() {
			if (this.hasmore) {
				this.getList()
			}
		},
		methods: {
			getBanner() {
				this.$request({
					url: this.$api.jimai.index_part,
					data: {
						mch_id: this.mch_id
					}
				}).then(info => {
					
					if(this.mch_id == '0'){
						this.banner = info.data.setting.platform[`banner${this.type}`]
					}else{
						this.banner = info.data.setting.mch[`banner${this.type}`]
					}
				}).catch(info => {})
			},
			getList() {
				this.$showLoading();
				this.$request({
					url: this.$api.jimai.goodsList,
					data: {
						type: this.type,
						mch_id: this.mch_id,
						page: this.page,
						limit: this.limit
					}
				}).then(info => {
					this.page++
					this.$hideLoading();
					if (info.code === 0) {
						if (info.data.list) {
							this.list = this.list.concat(info.data.list)
							this.hasmore = info.data.list.length == this.limit
						} else {
							this.hasmore = false
						}

					}
				}).catch(info => {
					this.$hideLoading();
				})
			},
			totiyan(type) {
				uni.navigateTo({
					url: '/plugins/jimai/tyList?type=' + type
				})
			}
		},
	}
</script>

<style scoped>
	.swiper {
		width: 100%;
		height: 300upx;
	}

	.swiper image {
		width: 100%;
		height: 100%;
	}

	page {
		background: #f7f7f7;
	}
</style>
